<?php
session_start();
include("UserIncludes/DbConfig.php");
echo '<pre>';
print_r($_REQUEST);
echo '</pre>';

// if($_REQUEST['mode']=='thank_you')
// {
	$x_exp_date =$_REQUEST['ceMonth'] . $_REQUEST['ceYear'];
	$rsCart=mysql_fetch_array(mysql_query("select sum(total_amount) from tblordertemp where session_id='".session_id()."'"));
		
	$total_cart_amount =$rsCart['0'];

	$row_billing = mysql_fetch_array(mysql_query("SELECT *  FROM payment_method WHERE userId = '".$_SESSION['siteuserId']."'"));
	

	$expiry_date=$_REQUEST[ceMonth]."-".$_REQUEST[ceYear];
	
	$sqlInsertOrder ="insert into tblordermaster  set paymentId='".$row_billing[paymentId]."'";
	$sqlInsertOrder .=", order_date='".date("y-m-d")."'";
	$sqlInsertOrder .=", total_amount='".$total_cart_amount."'";
	$sqlInsertOrder .=", grand_total='".$total_cart_amount."'";
	$sqlInsertOrder .=", payment_method='".$_REQUEST[payment_method]."'";
	$sqlInsertOrder .=", card_type='".$_REQUEST[card_type]."'";
	$sqlInsertOrder .=", card_no='".$_REQUEST[card_no]."'";
	$sqlInsertOrder .=", siteuserId='".$_SESSION['siteuserId']."'";
	$sqlInsertOrder .=", expire_date='".$expiry_date."'";

	if(mysql_query($sqlInsertOrder) or die(mysql_error()))//insert into order master table
			{
			$order_id=mysql_insert_id();
			$rsFetchCart=mysql_query("select * from tblordertemp  where session_id='".session_id()."'");
			while($rowFetchCart=mysql_fetch_array($rsFetchCart))
			{
			$rsInsertProduct=mysql_query("insert into tblorderdetail set order_id='".$order_id."',
			siteuserId='".$rowFetchCart['siteuserId']."',
			adsiteId='".$rowFetchCart[adsiteId]."',
			adspaceId='".$rowFetchCart[adspaceId]."',
			advertiseId='".$rowFetchCart[advertiseId]."',
			adspace_price='".$rowFetchCart[adspace_price]."',
			payment_reason='Buy adspace',
			payout_date=NOW(),
			type='cr',
			payment_status='Y',
			add_qty='".$rowFetchCart[Quentity]."'") or die(mysql_error());//fetch product details from cart and insert into order product details table
			
			$rsUpdateProduct=mysql_query("update advertise_master set advertiseStatus='Y' where advertiseId='".$rowFetchCart[advertiseId]."'");
	
					}

				$sqlDeleteCart="delete from tblordertemp where session_id='".session_id()."'";//empty cart
				mysql_query($sqlDeleteCart);
// 					if(mysql_query($sqlDeleteCart) or die(mysql_error()))
// 					{
// 						$_SESSION['shipping_id']="";
// 						unset($_SESSION['shipping_id']);
// 						$_SESSION['billing_id']="";
// 						unset($_SESSION['billing_id']);
// 					}
// 					echo "<script language='javascript'>document.location='thankYou.php?msg=paymentSuccess'</script>";
				}
// }
?>